package com.example.es_promotion.controller;

import com.example.es_promotion.entity.Promotion;
import com.example.es_promotion.service.PromotionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/promotions")
@RequiredArgsConstructor
public class AdminPromotionController {
    
    private final PromotionService promotionService;
    
    @PostMapping
    public Promotion createPromotion(@RequestBody Promotion promotion) {
        return promotionService.createPromotion(promotion);
    }
    
    @PutMapping("/{id}")
    public Promotion updatePromotion(@PathVariable Long id, @RequestBody Promotion promotion) {
        return promotionService.updatePromotion(id, promotion);
    }
    
    @PostMapping("/{id}/approve")
    public void approvePromotion(@PathVariable Long id) {
        promotionService.approvePromotion(id);
    }
    
    @PostMapping("/{id}/terminate")
    public void terminatePromotion(@PathVariable Long id) {
        promotionService.terminatePromotion(id);
    }
    
    @GetMapping
    public List<Promotion> getAllPromotions() {
        return promotionService.getAllPromotions();
    }
    
    @GetMapping("/{id}")
    public Promotion getPromotion(@PathVariable Long id) {
        return promotionService.getPromotionById(id);
    }
}